
<template src="./tpl.html"></template>
<script>
import {
  CONSENT_GRANT_USER_ROLE,
  CONSENT_GET_USER_LIST,
  CONSENT_GET_ZK_LIST,
  CONSENT_GET_ROLE_LIST
} from "_SERVICES/api";
import { trimAll } from "UTILS/string";
import { isvalidateNum2 } from "UTILS/validate";
import { timeFormatter } from "UTILS/format";

import { getStorage } from "UTILS/util";

import page from "@/modules/CST/mxins/page";
export default {
  name: "user",
  mixins: [page],
 
  data() {
    return {
      formInline: {
        YHXM: "",
        YHZH: "",
        ZKID:null
      
      },
      ZK_LIST:[],
      dialogVisible: false,
      editInfo:{},
      rules:{},
      roleList:[],
      headers: [
        {
          label: "YHID",
          prop: "YHID",
        },
        {
          label: "姓名",
          prop: "YHXM",
        },
        {
          label: "用户账号",
          prop: "YHZH",
        },
        {
          label: "专科",
          prop: "ZKMC",
        },
        {
          label: "角色",
          prop: "ROLE_NAME",
        },
       
      ],
      saveLoading: false
    };
  },
  created() {
    this.get_zkid_list();
    this.get_role_list();
    this.getList()
  },
  mounted() {},
  methods: {
    getList() {
      this.listLoading = true;
      let params = {
        ...this.formInline
      };
      Object.assign(params, this.getParams());

      return CONSENT_GET_USER_LIST(params)
        .then((res) => {
          this.listLoading = false;
          this.listQuery.totalNum = res.totalNum;
          this.tableData = res.data;
        })
        .catch((res) => {
          this.tableData = []
          this.listLoading = false;
          this.downloadLoading = false;
      });
    },
    get_role_list(){
      CONSENT_GET_ROLE_LIST({
        download: 1
      }).then((res)=>{
        this.roleList = res.data || []
      });
    },
    get_zkid_list() {
      CONSENT_GET_ZK_LIST({}).then((res) => {
        console.log("获取专科列表成功");
        this.ZK_LIST = res.data || [];
      });
    },
    editRow(row){
      this.dialogVisible = true;
      this.editInfo = {...row};
    },
    sure(){
      console.log(this.editInfo)
      this.saveLoading = true;
      CONSENT_GRANT_USER_ROLE({
        SQ_YHID: this.editInfo.YHID,
        ROLE_ID: this.editInfo.ROLE_ID
      }).then((res)=>{
        this.saveLoading = false;
        this.$message.success("修改角色成功")
        this.dialogVisible = false;
        this.getList()
      }).catch((e)=>{
        this.saveLoading = false;
      })
    }
  },
};
</script>

<style lang="less">
</style>
